import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import 'lib-flexible/flexible'
import VueLazyLoad from 'vue-lazyload'
import VueRouter from 'vue-router'

import { 
  Tabbar, 
  TabbarItem, 
  Icon,
  Search,
  NavBar,
  Toast,
  Swipe,
  SwipeItem,
  Lazyload,
  Tab,
  Tabs,
  Form,
  Field,
  Button,
  Badge,
  Tag,
  Grid,
  GridItem,
  ShareSheet, 
  Cell,
  CellGroup,
  Sidebar,
  SidebarItem,
  Collapse,
  CollapseItem,
  Popup,
  ImagePreview,
  NoticeBar       
} from 'vant';


Vue
 .use(Tabbar)
 .use(TabbarItem)
 .use(Icon)
 .use(Search)
 .use(NavBar)
 .use(Swipe)
 .use(SwipeItem)
 .use(Lazyload )
 .use(Tab)
 .use(Tabs)
 .use(Form)
 .use(Field )
 .use(Button )
 .use(Badge )
 .use(Tag )
 .use(Grid)
 .use(GridItem )
 .use(ShareSheet)
 .use(Toast)
 .use(Cell)
 .use(CellGroup)
 .use(Sidebar)
 .use(SidebarItem )
 .use(Collapse)
 .use(CollapseItem)
 .use(Popup )
 .use(ImagePreview )
 .use(NoticeBar )
 Vue.use(VueLazyLoad,{
  error: require('./assets/defaultAvatar.png'),  //报错需要的图片
  loading:require('./assets/defaultAvatar.png')// 替换需要的图片
})
Vue.config.productionTip = false
//设置默认基础请求路径
axios.defaults.baseURL = 'https://apis.netstart.cn/douguo/';

// 添加请求拦截器（请求之前触发）
axios.interceptors.request.use(config => {




   //启动加载提示
   Toast.loading({
    message: '加载中...',
    duration: 0
  });
  return config;
},error =>{
  Toast.clear();
  return Promise.reject(error)
});
// 添加响应拦截器(响应之前触发)
axios.interceptors.response.use(response => {
  // 对响应数据做什么
   //关闭加载提示
   Toast.clear();
 return response;
},error => {
  Toast.clear();
  return Promise.reject(error);
})
Vue.use(VueAxios, axios)

//防止点击相同路由出现错误(此错误不会后续操作)
let naturalPush = VueRouter.prototype.push;

// 重写路由的push办法，在push办法添加catch办法俘获错误
VueRouter.prototype.push = function (location){
  return naturalPush.call(this , location).catch(err =>{});
}
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
